<style>
    .show{display: inherit}
    .hide{display: none}
    table tr td,table tr th{width: 5%}
    .layui-btn{margin-right: 10px}
    /*.layui-table-cell {overflow-x: hidden;overflow: inherit; }*/
</style>


<form class="layui-form" action="" method="post" id="editForm">
	<div class="layui-inline removeStat">
        <label class="layui-form-label">入库到货仓</label>
        <div class="layui-input-inline">
            {:Form::select('storehouse_id', '', $storehouseKV, '', '', 'lay-filter="storehouse-id" lay-verify="required"')}

        </div>
    </div>
    <div class="layui-inline removeStat">
        <label class="layui-form-label">入库货架</label>
        <div class="layui-input-inline">
            {:Form::select('storeshelf_id', '', [], '', '')}
        </div>
    </div>
	<table id="dataTable" lay-filter="demoEvent"></table>
    

    <div class="pop-bottom-bar">
    	<input type="hidden" name="checkin_action_ids" id="checkin_action_ids" value="">
        <input type="hidden" name="batch_number" value="{$batch_number}">
<!--        <input type="hidden" name="action" value="docheckin">-->
<!--        <input type="hidden" name="applyids" value="">-->
<!--        <input type="hidden" name="in_factory" value="">-->
<!--        <input type="hidden" name="stock" value="">-->
        <button type="button" class="layui-btn layui-btn-normal" onclick="checkdata()" lay-submit="" lay-filter="checkSubmitData">提交执行入库</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>
{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a data-href="{:url('stockActionDelete')}?id={{d.id}}" class=" layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
	<a href="{:url('index')}?action=printrOverMaterialLabel&id={{d.id}}&batch_number={{d.batch_number}}" target="_blank" class=" layui-btn layui-btn-xs layui-bg-orange">打印贴标</a>
</script>

<script type="text/html" id="picTpl">
    <span class="lay-pic-container" src="{{ d.pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">

	</span>
</script>
<script type="text/html" id="nameTpl">
    {{layui.tool.formatMaterialType(d.material_type,'',2)}}<span class='copy-item'>{{d.material_name}}</span>
</script>
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/vue@3.2.26/dist/vue.global.js"></script>
<script type="text/javascript">
    var storeshelfMap = {:json_encode($storeshelfMap)};
    layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;
        var initialize=0,second_initialize=0,first_init=0,changetab=0;
        laydate.render({
            elem: '#create_date_range'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range').val(value);
                $('#layui-laydate1').remove();//关闭面板
            }
        });
        laydate.render({
            elem: '#create_date_range1'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range1').val(value);
                $('#layui-laydate2').remove();//关闭面板
            }
        });

        laydate.render({
            elem: '#stall_order_time'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#stall_order_time').val(value);
                $('#layui-laydate3').remove();//关闭面板
            }
        });


        table.render({
            elem: '#dataTable'
            ,url: '{:url("",['batch_number'=>$batch_number])}' //数据接口
            ,page: true //开启分页
            //,skin: 'row'
            ,even: true
            ,limit: 100
            ,limits: [100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'

            ,defaultToolbar: ['exports', 'print']
            ,cols: [[ //表头
				{type:'checkbox',field:"id"}
                ,{field: 'stock_m_type_txt', title: '物料类型',wdith:60}
                ,{field: 'material_name', title: '材料名称',templet:'#nameTpl',width:150}
                ,{field: 'model', title: '型号',width:170}
                ,{field: 'cloth_num', title: '物料ID'}
                ,{field: 'color', title: '颜色'}
                ,{field: 'unit', title: '单位'}
                ,{field: 'use_num', title: '入库数量',edit:'text',style:'border-bottom:2px dotted #5FB878;'}
                ,{field: 'ft_name', title: '工厂'}
                // ,{field:'pic',title : '图片', templet:'#picTpl',width:110}
                // ,{field: '', title: '发起人',width:150}
                // ,{field: '', title: '发起时间',width:150}
                // ,{field: '', title: '材料名称/型号/色号/颜色',width:200}
                // ,{field: '', title: '物料SKU',width:60}
                // ,{field: '', title: '采购批号',width:60}
                // ,{field: '', title: '面料ID',width:60}
                // ,{field: '', title: '入库类型',width:60}
                // ,{fieldd: '', title: '订单号/SKU/帐号',width:150}
                // ,{field: '', title: '工厂',width:100}
                // ,{fiel: '', title: '入库米数',width:60}
                // ,{field: 'col4', title: '状态',width:60 ,templet:function(d){ return'待发起'}}
                ,{field: 'col3', title: '操作',templet:'#buttonTpl',width:140}
            ]]
            ,done: function(res, curr, count){
                var data=res.data;
                var status=res.status;
                for (var i in data){
                    $('#stall-ids-'+data[i]['id']).val(data[i]['stall_id']);
                }
                layui.form.render();
                if(status==1){
                    $('table tr').each(function(i){
                        var remove_field=['time_payment'
                        ];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                    $('.back').show();
                    $('.account-payment').show();
                }else if(status==2){
                    $('table tr').each(function(i){
                        var remove_field=['time_submit','username'
                        ];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                    $('.back').remove();
                    $('.account-payment').remove();
                    $('.bill-list-a').attr('href',$('.bill-list-a').attr('href')+'&status_real=0&status_type=1') ;
                }
                table.on('edit(demoEvent)', function(obj){
                    var value = obj.value //得到修改后的值
                        ,d = obj.data //得到所在行所有键值
                        ,field = obj.field; //得到字段
                    var id=d.id;

                    $.ajax({
                        type: "POST",
                        url: "{:url('stockActionCheckIn')}",
                        data: "action=changeCheckInNum&id="+d.id+"&field="+field+"&value="+value,
                        dataType:"json",
                        success: function(res){
                            if (res.code == 1) {
                                layer.msg(res.msg, {icon: 1});
                            } else {
                                layer.msg(res.msg, {icon: 2,anim: 6});
                            }
                        }
                    });
                });
            }
        });
		
		form.on('submit(checkSubmitData)', function (data) {
			var url = data.field.url;
			if($(".layui-form-checked").size()<=0){
				layer.msg('请选择要入库的数据', {icon: 2,anim: 6});return false;
			}
			var checkids='';
			var that = $(document);
			var tableObj = that.attr('data-table') ? that.attr('data-table') : 'dataTable';
			var checkStatus = table.checkStatus(tableObj);
			console.log(checkStatus);
			for(var i=0;i<checkStatus.data.length;i++){
				checkdata=checkStatus.data;
				checkids+=checkdata[i]['id']+',';
			}
			//$("#checkin_action_ids").val(checkids);
			data.field.checkin_action_ids=checkids
			$.ajax({
	 		   type: "POST",
	 		   url: "{:url('stockActionCheckIn')}",
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
					 layer.msg(res.msg, {icon: 1});
					 parent.reloadTable();
					 setTimeout("parent.layui.layer.closeAll()",2000);
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			
			return false;
		});


        // 货仓下拉切换
        form.on('select(storehouse-id)', function(data){
            console.log(data);
            var optionArr = storeshelfMap[data.value];
            var option = '';
            for(var i in optionArr) {
                option += '<option value="'+i+'">'+optionArr[i]+'</option>';
            }
            $("select[name=storeshelf_id] option").remove();
            $('select[name=storeshelf_id]').append(option);
            form.render();
        });
    });

</script>